#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn][15];
LL a[maxn];
int main(void){
  LL n,m,k;cin>>n>>m>>k;
  for(LL i=1;i<=n;i++){
     cin>>a[i];
  }
  memset(dp,-0x3f,sizeof(dp));
  dp[0][m-1]=0;
  LL ans=0;
  for(LL i=1;i<=n;i++){
     for(LL j=0;j<=m-1;j++){
        if(j==0) dp[i][j]=max(dp[i-1][m-1]+a[i]-k,a[i]-k);
        else dp[i][j]=dp[i-1][j-1]+a[i];
        ans=max(ans,dp[i][j]);
     }
  }
  cout<<ans<<"\n";
  return 0;
}
